//
//  SearchDetailViewController.m
//  Cooking
//
//  Created by dlios on 15-10-8.
//  Copyright (c) 2015年 ZP.Y. All rights reserved.
//

#import "SearchDetailViewController.h"
#import "AsyncGetConnection.h"
#import "SearchModel.h"
#import "MBProgressHUD.h"

@interface SearchDetailViewController ()<UIWebViewDelegate,MBProgressHUDDelegate>

@property(nonatomic ,retain)UIWebView *web;
@property(nonatomic ,retain)SearchModel *model;
@property(nonatomic ,retain)MBProgressHUD *HUD;
@end

@implementation SearchDetailViewController
- (void)dealloc
{
    [_HUD release];
    [_model release];
    [_web release];
    [super dealloc];
}

- (instancetype)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
    self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
    if (self) {
//         self.navigationController.navigationBar.hidden =  YES;
    
    }
    return self;
}

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
//     self.navigationController.navigationBar.hidden =  YES;
    self.navigationItem.title = self.model.title;
    
}
// 创建加载图案
-(void)creatLoading
{

    self.HUD = [[MBProgressHUD alloc] init];
    _HUD = [[MBProgressHUD showHUDAddedTo:self.view animated:YES] retain];
    _HUD.delegate = self;
    _HUD.backgroundColor = [UIColor clearColor];
    _HUD.detailsLabelText = @"努力加载中...";
    _HUD.dimBackground = YES;

    
}
-(void)viewWillAppear:(BOOL)animated
{
    self.tabBarController.tabBar.hidden = NO;
}

-(void)creat:(NSString *)url
{
    self.web = [[[UIWebView alloc]initWithFrame:CGRectMake(0, -44, self.view.frame.size.width, self.view.frame.size.height)]autorelease];
    self.web.scrollView.bounces = NO;
    
    [self.view addSubview:_web];
    self.web.delegate = self;
    NSURLRequest *request = [NSURLRequest requestWithURL:[NSURL URLWithString:url]];
    [self.web loadRequest:request];
}

-(void)webViewDidStartLoad:(UIWebView *)webView
{
    [self creatLoading];
}

-(void)webViewDidFinishLoad:(UIWebView *)webView
{
    self.HUD.hidden = YES;
}

-(void)receveSearchModel:(SearchModel *)model
{
    self.model = [[[SearchModel alloc]init]autorelease];
    self.model = model;

    //methodName=DishesView&dishes_id=2800&version=4.02&
    NSMutableDictionary *dic =[NSMutableDictionary dictionary];
    [dic setObject:@"DishesView" forKey:@"methodName"];
     [dic setObject:model.dishes_id forKey:@"dishes_id"];
     [dic setObject:@"4.02" forKey:@"version"];
    [AsyncGetConnection asyncPOSTConnectionWithURL:@"http://api.izhangchu.com" parameters:dic block:^(NSData *data) {
        
        NSDictionary *dic = [NSJSONSerialization JSONObjectWithData:data options:NSJSONReadingMutableContainers error:nil];
        NSDictionary *dic1 = [dic objectForKey:@"data"];
        NSString *url = [dic1 objectForKey:@"share_url"];
        [self creat:url];
    }];
    
}


- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
